﻿#region Header

// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

using System;
using System.Globalization;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using DesignByContract;

namespace Majesty_of_Omega.GUI.ValueConverters
{
    /// <summary>
    /// Converts a Tech-Icon from the \Graphics\Tech - Directory to a <see cref="BitmapImage"/>
    /// </summary>
    public class TechIconToImageConverter : UriToImageConverter
    {
        /// <summary>
        /// Converts a Tech-Icon from the \Graphics\Tech - Directory to a <see cref="BitmapImage"/>.
        /// A BitmapImage can be attached to the Image.Source Report.
        /// </summary>
        /// <param name="value">Name of the tech icon</param>
        /// <param name="targetType">must be ImageSource</param>
        /// <param name="parameter">currently not used</param>
        /// <param name="culture">currently not used</param>
        /// <returns>Valid BitmapImage</returns>
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Require.IsTrue(value is string);
            Require.AreEqual(typeof(ImageSource), targetType);
            string uri = (string) value;

            BitmapImage image = LoadBitmapImage(@"\Graphics\Tech\" + uri + ".png");
            return image;
        }

    }
}